package cn.singno.bob.web.editor;

import java.beans.PropertyEditorSupport;

import org.apache.commons.lang3.StringUtils;
import org.jsoup.Jsoup;
import org.jsoup.safety.Whitelist;

public class FloatEditor extends PropertyEditorSupport{

	@Override
	public String getAsText() {
		Float value = (Float)getValue();
		if(value == null){
			return null;
		}
		return value.toString();
	}
	
	@Override
	public void setAsText(String arg0) throws IllegalArgumentException {
		if(StringUtils.isBlank(arg0)){
			setValue(null);
		}else{
			arg0 = Jsoup.clean(arg0, Whitelist.relaxed());
			try{
				setValue(Float.valueOf(arg0));
			}catch(Exception e){
				setValue(null);
			}
		}
	}
}
